<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工单列表列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>衡器号：</label>
                                <select name="waCode" th:with="type=${@commdict.getDictList('womp_weighing_apparatus,code,name')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="state" th:with="type=${@dict.getType('work_order_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>日期范围：</label>
	                            <input type="text" class="input-sm" id="laydate-startTime" name="beginDate" placeholder="yyyy-MM-dd"/>
	                            <span>到</span>
	                            <input type="text" class="input-sm" id="laydate-endTime" name="endDate" placeholder="yyyy-MM-dd"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
    	var workOrderHandleFlag = [[${@permission.hasPermi('womp:workOrder:handle')}]];
        var editFlag = [[${@permission.hasPermi('womp:workOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('womp:workOrder:remove')}]];
        var waCodeDatas = [[${@commdict.getDictList('womp_weighing_apparatus,code,name')}]];
        var ecodeDatas = [[${@commdict.getDictList('womp_element,code,name')}]];
        var stateDatas = [[${@dict.getType('work_order_state')}]];
        var prefix = ctx + "realtime";

        $(function() {
            var options = {
                url: prefix + "/workOrderList",
                modalName: "工单列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'wa_code',
                    title: '衡器号',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(waCodeDatas, value);
                    }
                },
                {
                    field: 'alarm_id',
                    title: '告警编号',
                    visible: false
                },
                {
                    field: 'ecode',
                    title: '告警要素',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(ecodeDatas, value);
                    }
                },
                {
                    field: 'handler',
                    title: '负责人'
                },
                {
                    field: 'handle_content',
                    title: '处理方法'
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stateDatas, value);
                    }
                },
                {
                    field: 'create_by',
                    title: '创建人'
                },
                {
                    field: 'create_time',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openWorkOrderHandle(\'' + row.id + '\')"><i class="fa fa-edit"></i>详细</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
            
            layui.use('laydate', function(){
         		var laydate = layui.laydate;
	            var startDate = laydate.render({
			        elem: '#laydate-startTime',
			        max: $('#laydate-endTime').val(),
			        theme: 'molv',
			        trigger: 'click',
			        done: function(value, date) {
			            // 结束时间大于开始时间
			            if (value !== '') {
			                endDate.config.min.year = date.year;
			                endDate.config.min.month = date.month - 1;
			                endDate.config.min.date = date.date;
			            } else {
			                endDate.config.min.year = '';
			                endDate.config.min.month = '';
			                endDate.config.min.date = '';
			            }
			        }
			      });
	       		
			      var endDate = laydate.render({
			        elem: '#laydate-endTime',
			        min: $('#laydate-startTime').val(),
			        theme: 'molv',
			        trigger: 'click',
			        done: function(value, date) {
			            // 开始时间小于结束时间
			            if (value !== '') {
			                startDate.config.max.year = date.year;
			                startDate.config.max.month = date.month - 1;
			                startDate.config.max.date = date.date;
			            } else {
			                startDate.config.max.year = '';
			                startDate.config.max.month = '';
			                startDate.config.max.date = '';
			            }
			        }
			    });
            });
        });
		function openWorkOrderHandle(workOrderId){
			$.modal.open('工单处理', 'realtime/toWorkOrderHandle?workOrderId=' + workOrderId, '1200', '600');
		}
    </script>
</body>
</html>